import {
  getSchoolListRequest,
  getOtherNewsListRequest
} from '../../api/main'
const schoolCacheKey = "schoolnews"
const othernewsCacheKey = "othernews"
var data = require('../../utils/news-data.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    newsList: data.newsList,
    banner: [
      "imgs/img1.jpg",
      "imgs/img2.jpg",
      "imgs/img3.jpg"
    ],
    list: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getList(),
    console.log(this.data.newsList)

  },

  gotoNewsDetail: function(e){
    var index = e.currentTarget.dataset.index;
    console.log("index==" + index)
    wx.navigateTo({
      url: '../newsDetail/newsDetail?index='+index,
    })
  },
  onImageError: function (e) {
    //var writerIndex = e.currentTarget.dataset.writerIndex;
    var newsIndex = e.currentTarget.dataset.newsIndex;
    var newsList = this.data.newsList;
    // console.log(newsIndex)
    if (newsIndex){
      var newsImageError = newsList[newsIndex];
      newsImageError.newsUrl = '../../asset/imgs/error_img.jpg';
    }
    // if (writerIndex){
    //   var writersImageError = newsList[writerIndex];
    //   writersImageError.writersUrl = '../../images/error_img.jpg';
    // } 
    this.setData({
      newsList: newsList
    })
  },


  getList() {
    const cache = wx.getStorageSync(schoolCacheKey)
    if (cache) {
      this.setData({
        list: cache
      })
      return
    }
    //this.update()
  },


  // 切换类型
  changeScoreType(e) {
    const type = e.currentTarget.dataset.type
    this.setData({
      type
    })
    this.getList()
  },

  changeTerm(e) {
    const termIndex = e.detail.value
    this.setData({
      termIndex
    })
  },

  // onClick(event) {
  //   wx.showToast({
  //     title: `点击标签 ${event.detail.name}`,
  //     icon: 'none',
  //   });
  // },
})